<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SoberPress &rsaquo; Installation</title>
<link rel="stylesheet" href="install.css" type="text/css" />

<?php
require_once ('config.php');
// set a hash
function make_seed()
{
  list($usec, $sec) = explode(' ', microtime());
  return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
$randval = rand();
$strHash = hash('md5', $randval);
$errors = 0;
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die ('Error connecting to mysql');
mysql_select_db(DB_NAME);
if (!$conn) {
  mysql_close($conn); //Ends the current connection to the database.
  echo "Cannot connect to the database!"; //Display the text inside the quotes.
}else{
$sql = 
"CREATE TABLE events (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  title varchar(100) NOT NULL,
  editHTML mediumtext NOT NULL,
  file varchar(100) DEFAULT NULL,
  tableID varchar(6) NOT NULL DEFAULT 'events',
  editor varchar(40) NOT NULL,
  editdate datetime NOT NULL,
  eventDate date NOT NULL,
  eventEndDate date NOT NULL,
  eventStartTime time NOT NULL,
  eventEndTime time NOT NULL,
  PRIMARY KEY (id),
  KEY editor (editor)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO events VALUES(1, 'The Recovery Show', '<p>Join us for a 75-minute presentation that incorporates puppets, music, audience participation and 12-Step humor. Some highlights of the show include &ldquo;working the 12-Steps in three and a half minutes&rdquo; and a guest appearance by &ldquo;Bud Wiser.&rdquo; The Recovery Show is based on the 12-Step program.</p>', 'recoveryshow.pdf', 'events', 'admin', '2011-12-08 07:39:04', '2012-01-01', '0000-00-00', '17:30:00', '19:00:00');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO events VALUES(2, 'Big Book Study', '<p>DAN McQ<br />WILL PRESENT A TWELVE WEEK BIG BOOK<br />STUDY COURSE<br />SATURDAYS, JANUARY 7th, 2012 TO MARCH 24th, 2012<br />10 AM TO 12 PM</p>', 'bbstudy.pdf', 'events', 'admin', '2011-12-08 07:41:21', '2012-01-12', '0000-00-00', '10:00:00', '12:00:00');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql =
"CREATE TABLE groups (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  groupname varchar(75) NOT NULL DEFAULT '',
  ir_fname varchar(15) NOT NULL DEFAULT '',
  ir_lname varchar(25) NOT NULL DEFAULT '',
  ir_home_phone varchar(15) NOT NULL DEFAULT '',
  ir_cell_phone varchar(15) NOT NULL DEFAULT '',
  ir_work_phone varchar(15) NOT NULL DEFAULT '',
  ir_email varchar(75) NOT NULL DEFAULT '',
  editor varchar(40) NOT NULL DEFAULT '0',
  editdate datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (id),
  KEY groupname (groupname)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql =
"CREATE TABLE links (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  page_id mediumint(9) NOT NULL,
  section_id mediumint(9) NOT NULL,
  record_order mediumint(9) NOT NULL,
  system_module varchar(25) DEFAULT NULL,
  title varchar(100) NOT NULL,
  url varchar(100) NOT NULL,
  enabled smallint(6) NOT NULL,
  tableID varchar(7) NOT NULL DEFAULT 'links',
  editor varchar(40) NOT NULL,
  editdate datetime NOT NULL,
  PRIMARY KEY (id)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql =
"CREATE TABLE locations (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  name varchar(50) NOT NULL DEFAULT '',
  address varchar(75) NOT NULL DEFAULT '',
  address2 varchar(50) NOT NULL DEFAULT '',
  city varchar(30) NOT NULL DEFAULT '',
  state char(2) NOT NULL DEFAULT '',
  zip varchar(10) NOT NULL DEFAULT '',
  phone varchar(15) NOT NULL DEFAULT '',
  website varchar(100) NOT NULL DEFAULT '',
  editor varchar(40) NOT NULL DEFAULT '0',
  editdate datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  KEY ID (id),
  KEY city (city)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql =
"CREATE TABLE meetings (
  id int(11) NOT NULL AUTO_INCREMENT,
  day tinyint(1) NOT NULL DEFAULT '0',
  mtime time NOT NULL DEFAULT '00:00:00',
  location_id mediumint(9) NOT NULL DEFAULT '0',
  group_id mediumint(9) NOT NULL DEFAULT '0',
  mtg_type_id mediumint(9) NOT NULL DEFAULT '0',
  open_closed varchar(7) NOT NULL DEFAULT '',
  men_women varchar(9) NOT NULL DEFAULT '',
  room varchar(75) NOT NULL DEFAULT '',
  hc char(1) NOT NULL DEFAULT '',
  editor varchar(40) NOT NULL DEFAULT '',
  editdate datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (id),
  KEY day (day)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql =
"CREATE TABLE meeting_resources (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  page_id mediumint(9) NOT NULL,
  section_id mediumint(9) NOT NULL,
  record_order mediumint(9) NOT NULL,
  system_module varchar(25) DEFAULT NULL,
  title varchar(100) NOT NULL,
  file varchar(100) NOT NULL,
  enabled smallint(6) NOT NULL,
  tableID varchar(7) NOT NULL DEFAULT 'links',
  editor varchar(40) NOT NULL,
  editdate datetime NOT NULL,
  PRIMARY KEY (id)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql =
"CREATE TABLE meeting_types (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  code varchar(15) NOT NULL DEFAULT '',
  description varchar(80) NOT NULL DEFAULT '',
  explanation varchar(100) NOT NULL DEFAULT '',
  editor varchar(40) NOT NULL DEFAULT '0',
  editdate datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (id)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql = "INSERT INTO meeting_types VALUES(1, 'D', 'Discussion', 'Discussion of any AA topic', 'sobernerd', '2011-03-24 19:35:22');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO meeting_types VALUES(2, 'St', 'Step', 'Step Meeting - Reading and discussion of the 12 & 12', 'sobernerd', '2007-03-24 19:36:54');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO meeting_types VALUES(3, 'BB', 'Big Book', 'Reading and discussing the Big Book - Alcoholics Anonymous', 'sobernerd', '2007-03-24 19:34:27');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO meeting_types VALUES(4, 'Sp', 'Speaker', 'Meeting where a speaker speaks most of the allotted time', 'sobernerd', '2007-03-24 19:36:48');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO meeting_types VALUES(5, 'T', 'Traditions', 'Reading and discussion of one of the 12 Traditions (usually the numer that =month we are in)', 'sobernerd', '2007-03-24 19:38:17');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO meeting_types VALUES(6, '11St', '11th Step', 'Reading and Discussion of 11th Step of AA', 'sobernerd', '2007-04-16 09:01:53');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO meeting_types VALUES(7, 'Bg', 'Beginners', 'Meeting designed for people new to AA', 'sobernerd', '2007-03-24 19:35:08');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql =
"CREATE TABLE modules (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  page_id mediumint(9) NOT NULL,
  section_id mediumint(9) NOT NULL,
  record_order mediumint(9) NOT NULL,
  system_module varchar(25) DEFAULT NULL,
  title varchar(100) NOT NULL,
  enabled smallint(6) NOT NULL,
  editHTML mediumtext NOT NULL,
  file varchar(100) DEFAULT NULL,
  tableID varchar(7) NOT NULL DEFAULT 'modules',
  editor varchar(40) NOT NULL,
  editdate datetime NOT NULL,
  PRIMARY KEY (id),
  KEY editor (editor)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO modules VALUES(2, 1, 0, 2, NULL, 'Call us 24 / 7 /365', 1, '<p><strong>Call the office anytime day or night.&nbsp; </strong></p>\r\n<p>If you need help right now then pick up the phone.&nbsp; Our volunteer staff will be happy to speak with you day or night.<strong><span style=\"color: #ff0000;\">&nbsp; (555) 555-5555</span><br /></strong></p>', '', 'modules', 'admin', '2011-12-08 10:32:15');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO modules VALUES(14, 1, 0, 4, NULL, 'AA Meeting Resources', 1, '<table style=\"width: 790px;\" border=\"0\">\r\n<tbody>\r\n<tr>\r\n<td style=\"text-align: left;\"><a href=\"public_html/uploads/preamble.pdf\" target=\"_blank\">AA Preamble</a></td>\r\n<td style=\"text-align: left;\"><a href=\"public_html/uploads/steps.pdf\" target=\"_blank\">12 Steps</a></td>\r\n<td style=\"text-align: left;\"><a href=\"public_html/uploads/steps.pdf\" target=\"_blank\">12 Traditions</a></td>\r\n</tr>\r\n<tr>\r\n<td><a href=\"public_html/uploads/how.pdf\" target=\"_blank\">How it Works</a></td>\r\n<td><a href=\"public_html/uploads/Promises.pdf\" target=\"_blank\">The Promises</a></td>\r\n<td><a href=\"public_html/uploads/concepts.pdf\" target=\"_blank\">12 Concepts of World Service</a></td>\r\n</tr>\r\n</tbody>\r\n</table>', '', 'modules', 'admin', '2011-12-08 10:29:57');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO modules VALUES(15, 1, 0, 3, NULL, 'AA Online Resources', 1, '<table border=\"0\">\r\n<tbody>\r\n<tr>\r\n<td><a href=\"http://www.aa.org\" target=\"_blank\">Alcoholics Anonymous World Services</a></td>\r\n</tr>\r\n<tr>\r\n<td><a href=\"http://www.aa.org/bbonline/\" target=\"_blank\">The Big Book On-line</a></td>\r\n</tr>\r\n<tr>\r\n<td><a href=\"http://www.aa.org/1212/\" target=\"_blank\">12 Steps On-line</a></td>\r\n</tr>\r\n</tbody>\r\n</table>', '', 'modules', 'admin', '2011-12-08 10:28:04');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql="INSERT INTO modules VALUES(17, 4, 0, 1, NULL, 'General Contact Information', 1, '<p>This is an area that you can enter general contact information such as the office number.</p>', '', 'modules', 'admin', '0000-00-00 00:00:00');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql =
"CREATE TABLE users (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  username varchar(40) DEFAULT NULL,
  password varchar(50) DEFAULT NULL,
  admin tinyint(1) NOT NULL DEFAULT '0',
  fname varchar(30) NOT NULL DEFAULT '',
  lname varchar(50) NOT NULL DEFAULT '',
  title varchar(50) NOT NULL DEFAULT '',
  regdate datetime NOT NULL DEFAULT '0000-00-00',
  email varchar(100) DEFAULT NULL,
  last_login datetime NOT NULL,
  listInContacts int(1) DEFAULT NULL,
  record_order mediumint(9) NOT NULL,
  junk varchar(256) NOT NULL,
  PRIMARY KEY (id)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql ="INSERT INTO users VALUES(5, 'billw', '6f42b631130aff29dd92d1812758c20e', 0, 'Bill', 'W', 'Founder', '2011-12-02 15:16:21', 'bill@aa.org', '2011-12-09 18:09:07', 1, 4, '');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql ="INSERT INTO users VALUES(6, 'Abe', '66d6c1820a6b57b3d72bdfa5feb4c4c8', 0, 'Abe', 'L', 'President', '2011-12-09 11:54:08', 'pres@soberpress.org', '2011-12-09 12:13:32', 1, 1, '');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql ="INSERT INTO users VALUES(7, 'george', '9b306ab04ef5e25f9fb89c998a6aedab', 0, 'George', 'W', 'Vice Pres', '2011-12-09 11:56:03', 'vp@soberpress.org', '2011-12-09 12:13:39', 1, 3, '');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql ="INSERT INTO users VALUES(8, 'thomas', 'ef6e65efc188e7dffd7335b646a85a21', 0, 'Thomas', 'J', 'Treasurer', '2011-12-09 11:58:28', 'tres@soberpress.org', '2011-12-09 12:13:46', 1, 5, '');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$sql ="INSERT INTO users VALUES(9, 'hillary', '6244ad4169ebba6e2aadf77aa94a9a8a', 0, 'Hillary', 'C', 'Sec', '2011-12-09 12:04:08', 'sec@soberpress.org', '2011-12-09 12:13:54', 1, 2, '');";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}

$sql =
"CREATE TABLE settings (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  orgname varchar(100) NOT NULL DEFAULT '',
  apikey varchar(256) NOT NULL DEFAULT '',
  timeZone varchar(75) NOT NULL DEFAULT '',
  siteName varchar(100) NOT NULL DEFAULT '',
  tagLine varchar(250) NOT NULL DEFAULT '',
  siteRoot varchar(250) NOT NULL DEFAULT '',
  randomkey varchar(250) NOT NULL DEFAULT '',
  PRIMARY KEY (id)
)";
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
$countSettingsRows = 0;
$sql= "SELECT id FROM settings";
$result = mysql_query($sql,$conn);
$countSettingsRows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
  {
  $settingsID = $row['id'];
  }

if ($countSettingsRows == 0) {
$sql =
"INSERT INTO settings (orgname, apikey, timeZone, siteName, tagLine, siteRoot, randomkey)
VALUES ('".$GLOBALS['ORG_NAME']."', '".API_KEY."', '".TIME_ZONE."', '".SITE_NAME."', '".SITE_DESC."', '".SITE_ROOT."', '".$strHash."')";
}else{
$sql =
"UPDATE settings SET orgname = '".$GLOBALS['ORG_NAME']."', apikey = '".API_KEY."', timeZone = '".TIME_ZONE."', siteName = '".SITE_NAME."', tagLine = '".SITE_DESC."', siteRoot = '".SITE_ROOT."', randomkey = '".$strHash."' WHERE id = '".$settingsID."'";
}
$result = mysql_query($sql,$conn);
if (mysql_errno($conn)){
	$errors++;
	echo mysql_errno($conn) . ": " . mysql_error($conn). "<br />";
}
mysql_close($conn);
}
if ($errors > 0) {
	echo 'There were '.$errors.' errors.<br /><br />';
	echo 'You can still try and <a href="../public_html/admin/admin.php?key='.$strHash.'">continue anyway</a>';
}else{
	echo 'Sucessful Intallation<br /><br />';
	echo '<a href="../public_html/admin/admin.php?key='.$strHash.'">continue to login</a>';
}?>